<?php
$link = mysqli_connect("localhost","root","root","2113");
$sql="SELECT * FROM messages";
$list=getList($link,$sql);
foreach($list as $k=>$v){
	$id = $v['id'];
	// echo $id;
	// echo "<hr>";
	$sql = "SELECT * FROM relpay WHERE mid=$id";
	$replayArr = getList($link,$sql);
	// print_r($replayArr);
	// echo "<hr>";
	// $list[$k] == $v;
	$list[$k]['replayList'] = $replayArr;
	// $v['replayList'] = $replayArr;
	
}

// echo "<pre>";
// print_r($list);
// echo "</pre>";
echo json_encode($list);



function getList($link,$sql){
    $res=mysqli_query($link,$sql);
    $arr=[];
    while($one=mysqli_fetch_assoc($res)){
        $arr[]=$one;
    }
   return $arr;
}



?>